/**
 *
 */
package com.ls.lserp.modules.order.web;

import com.ls.lserp.common.persistence.AjaxDone;
import com.ls.lserp.common.utils.excel.ExportExcel;
import com.ls.lserp.common.utils.excel.ImportExcel;
import com.ls.lserp.modules.order.entity.*;
import com.ls.lserp.modules.sys.entity.SendEmailMessage;
import com.ls.lserp.modules.sys.utils.SequenceUtil;
import groovy.util.ResourceException;

import java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import com.ls.lserp.modules.sys.utils.DictUtils;
import freemarker.template.Configuration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.collections.map.HashedMap;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.bind.annotation.*;


import com.ls.lserp.common.config.Global;
import com.ls.lserp.common.persistence.Page;
import com.ls.lserp.common.utils.DateUtils;
import com.ls.lserp.common.utils.ResourcesUtil;
import com.ls.lserp.common.utils.StringUtils;
import com.ls.lserp.common.web.BaseController;
import com.ls.lserp.dbaccess.Entity.StyleDesignHistoryEntity;
import com.ls.lserp.modules.common.entity.Material;
import com.ls.lserp.modules.job.web.MTMtoERPDataBaseSyncJob;
import com.ls.lserp.modules.order.service.OrderService;
import com.ls.lserp.modules.sys.utils.UserUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.RequestContext;


/**
 * 用户Controller
 *
 * @author zq
 * @version 2016-10-31
 */
@Controller
@RequestMapping(value = "${adminPath}/customization/order")
public class OrderController extends BaseController {
	/*质检缓存key*/
	public static final String CACHE_QUALITY_VALUE_MAP_34 = "qualityValueMap34";
	public static final String CACHE_QUALITY_VALUE_MAP_35 = "qualityValueMap35";
	public static final String CACHE_QUALITY_VALUE_MAP_36 = "qualityValueMap36";
	public static final String CACHE_QUALITY_VALUE_MAP_37 = "qualityValueMap37";
    private static final String REF = ".*Shirt.*";
    private Thread importOrder;
    private boolean stopFlag;
    private boolean completeFlag;
    @Autowired
    private OrderService orderService;

    private SXSSFWorkbook tempSk = new SXSSFWorkbook ();
    
    private SXSSFWorkbook sky = new SXSSFWorkbook ();
    
    private SXSSFWorkbook skCost = new SXSSFWorkbook ();

    @Autowired
    Configuration freemarkerConfiguration;
    @Autowired
    MTMtoERPDataBaseSyncJob mtMtoERPDataBaseSyncJob;

    /**
     * 进入一览页面
     *
     * @param id
     * @return
     */

    @ModelAttribute
    public Order get(@RequestParam(required = false) String id) {

        // 判断id是否为空
        if (StringUtils.isNotBlank (id)) {

            // 执行查询语句 查询基本信息
            return orderService.get (Long.parseLong (id));
        } else {

            // 若为空，实例化
            return new Order ();
        }

    }


    /**
     * 画面跳转用
     *
     * @param order
     * @param model
     * @return
     */

    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"order"})
    public String list(Order order, Model model) {
        // 获取店铺信息
        List <DesignOption> designOptionList = orderService.getdesignList ();
        // 前台select组件使用（店铺表）
        model.addAttribute ("designOptionList", designOptionList);
        model.addAttribute ("order", order);
        // 返回页面地址
        return "modules/order/orderList";
    }

    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"updateStatus"})
    public String updateStatus(Order order, Model model) {
        model.addAttribute ("order", order);
        // 返回页面地址
        return "modules/order/orderUpdateStatus";
    }
    
    @RequiresPermissions("customization:order:edit")
    @RequestMapping(value = {"saveStatus"})
    public String saveStatus(Order order, Model model,HttpServletRequest request, HttpServletResponse response) {
    	String flag = "false";
    	try {
    		
    		flag = 	orderService.updateStatus(order);
	
		} catch (Exception e) {
			logger.error(e.toString(), e);
		}
        // 返回页面地址
        return renderString(response, flag);
    }
    
    /**
     * @Title: 画面检索
     * @Description: 查询页面
     */

    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"searchList"})
    public String searchList(Order order, HttpServletRequest request, HttpServletResponse response, HttpSession session)
            throws ResourceException {
        Map <Object, Object> listMap = new HashMap <Object, Object> ();
        // ajax回调时使用的一览list名
        request.setAttribute (Global.LIST_NAME, "order");

        // 画面取得的检索项目

        String orderNO = order.getOrderNO ();
        String contractNo = order.getContractNo();
        String styleNoFrom = order.getStyleNoFrom ();
        String styleNoTo = order.getStyleNoTo ();
//		String customerName = order.getCustomerName();
        String shirtSgd = order.getShirtSgd ();
        String beginDate = order.getBeginDate ();
        /*String endDate = order.getEndDate ();*/
        String orderStatusCD = order.getOrderStatusCD ();
        String operating3Status = order.getOperating3Status();
        String strUri = request.getContextPath () + Global.getAdminPath ();
        // 拼接字符串供分页使用
        String searchParam = "&orderNO=" + orderNO + "&contractNo=" + contractNo + "&shirtSgd=" + shirtSgd + "&beginDate=" + beginDate 
        		+ "&orderStatusCD=" + orderStatusCD + "&styleNoFrom=" + styleNoFrom + "&styleNoTo=" + styleNoTo + "&operating3Status=" + operating3Status;
        // 放到Attribute里，使用Global类里面的SEARCH_PAEAM作为key
        request.setAttribute (Global.SEARCH_PAEAM, searchParam);
        session.setAttribute ("orderNO", orderNO);
        session.setAttribute ("shirtSgd", shirtSgd);
        session.setAttribute ("beginDate", beginDate);
        /*session.setAttribute ("endDate", endDate);*/
        session.setAttribute ("orderStatusCD", orderStatusCD);
        session.setAttribute ("styleNoFrom", styleNoFrom);
        session.setAttribute ("styleNoTo", styleNoTo);
        session.setAttribute ("contractNo", contractNo);
        // 面料类型：面料
        order.setMaterialType (Long.parseLong (ResourcesUtil.getConfig ("material_type_material")));
        // 查询一览页面数据
        Page <Order> page = orderService.findList (new Page <Order> (request, response), order);
        List <DesignOption> designOptionList = orderService.getdesignList ();
        // 读取文件生成字符串
        String strHtml = "";
        try {
            Map <String, Object> map = new HashedMap ();
            map.put ("adminUri", strUri);
            map.put ("designOptionList", designOptionList);
            map.put ("orders", page.getList ());
            map.put ("pageNo", page.getPageNo ());
            map.put ("pageSize", page.getPageSize ());

            strHtml = FreeMarkerTemplateUtils.processTemplateIntoString (
                    freemarkerConfiguration.getTemplate ("Order.ftl"), map);
        } catch (Exception e) {
        	logger.error (e.getMessage (), e);
        }

        listMap.put ("order", strHtml);
        listMap.put ("page", page.getHtml ());
        // ajax返回结果
        return renderString (response, listMap);
    }

    /**
     * @Title: 插入内部订单号
     */

	/*@RequiresPermissions("customization:order:edit")
    @RequestMapping(value = { "insertStyleNo" })
	@ResponseBody*/
    /*public String insertStyleNo(Order order, HttpServletRequest request, HttpServletResponse response){
        orderService.insertStyleNo(order);
		// 读取文件生成字符串
		return renderString(response, "");
	}*/

    /**
     * 功能：Java读取txt文件的内容 1：先获得文件句柄 2：获得文件句柄当做是输入一个字节码流，需要对这个输入流进行读取
     * 3：读取到输入流后，需要读取生成字节流
     *
     * @param filePath
     * @return html
     */
    public String readTxtFile(String filePath) {
        String strHtml = "";
        try {
            String encoding = "UTF-8";
            File file = new File (filePath);
            // 判断文件是否存在
            if (file.isFile ()) {
                InputStreamReader read = new InputStreamReader (
                        // 考虑到编码格式
                        new FileInputStream (file), encoding);
                BufferedReader bufferedReader = new BufferedReader (read);
                String lingText = null;
                while ((lingText = bufferedReader.readLine ()) != null) {
                    strHtml += lingText;
                }
                read.close ();
            } else {

            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return strHtml;
    }


    /**
     * 导出订单信息
     *
     * @param session
     * @param response
     * @return
     * @throws IOException
     * @throws ResourceException
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"exportOrder"})
    @ResponseBody
    public String exportOrder(Order order,HttpServletResponse response, HttpSession session)throws Exception {
        Map <Object, Object> listMap = new HashMap <Object, Object> ();
        try {
            SXSSFWorkbook sk = new SXSSFWorkbook ();
            this.orderService.exportOrder (sk, order);
            tempSk = sk;
            listMap.put ("FLG", "OK");
        } catch (Exception e) {
            listMap.put ("FLG", "NG");
            logger.error (e.getMessage (), e);
        }
        // ajax返回结果
        return renderString (response, listMap);
    }

    /**
     * Excel下载
     *
     * @param response
     * @return
     * @throws Exception
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"excelDownload"})
    public void personalmanagerDownload(HttpServletResponse response, HttpServletRequest request)
            throws Exception {
        String fileName = "流水线检查单.xlsx";
        response.reset ();
        response.setContentType ("application/octet-stream; charset=utf-8");
        response.setCharacterEncoding ("UTF-8");
        response.setHeader ("Content-Disposition", "attachment; filename=" + new String (fileName.getBytes (), "ISO-8859-1"));
        tempSk.write (response.getOutputStream ());
    }

    /**
     * 取得主表信息
     *
     * @param order
     * @return
     */
    public Order get(@RequestParam(required = false) Order order) {

        if (order == null) {
            return new Order ();
        }

        if (order.getId () != null) {
            order.setMaterialType (Long.parseLong (ResourcesUtil.getConfig ("material_type_material")));
            order = orderService.findOrder (order);
            return order;
        } else {
            // 店铺名称
            order.setShopId (UserUtils.getUser ().getShop ().getId ());
            return order;
        }
    }

    /**
     * 查看订单-基本信息-初始方法
     *
     * @param order
     * @param model
     * @param session
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"formShow"})
    public String formShow(Order order, Model model, HttpSession session) {

        try {

            order = get (order);
            // 店铺名称
            order.setShopName (UserUtils.getUser ().getShop ().getShopName ());
            // 登录用户
            order.setUserName (UserUtils.getUser ().getFirstName () + UserUtils.getUser ().getLastName ());
            // 项目及费用显示
            List <DesignOption> optionListAll = this.orderService.findDesignOptionByOrderId (order);
            model.addAttribute ("optionListAll", optionListAll);

            // 选项Order
            Order optionOrder = new Order ();
            // 面料
            Order orderCreate = new Order ();
            orderCreate.setId (order.getFabricId ());
            Material material = orderService.searchInfoByMaterialId (orderCreate);
            order.setMaterial (material);
            model.addAttribute ("material", material);


            // 放入session中，以备导出用
            session.setAttribute ("myUpdateOrder", order);

            // 项目分类CD--款式定制
            order.setItemCategoryCd (ResourcesUtil.getConfig ("item_type_cd-10"));
            // 根据订单查询设计信息
            List <DesignOption> optionList = this.orderService.findDesignOptionByOrderId (order);
            // 前台显示用
            model.addAttribute ("optionList", optionList);

            optionOrder = resolveDesignInfo (order, optionList, ResourcesUtil.getConfig ("item_type_cd-10"));
            order.setStyleItemList (optionOrder.getStyleItemList ());
            order.setStyleOptionList (optionOrder.getStyleOptionList ());


            // 项目分类CD--辅料
            order.setItemCategoryCd (ResourcesUtil.getConfig ("item_type_cd-20"));
            // 根据订单查询设计信息
            List <DesignOption> optionList2 = this.orderService.findDesignOptionByOrderId (order);
            // 前台显示用
            model.addAttribute ("optionList2", optionList2);

            optionOrder = resolveDesignInfo (order, optionList2, ResourcesUtil.getConfig ("item_type_cd-20"));
            order.setAccessoriesItemList (optionOrder.getAccessoriesItemList ());
            order.setAccessoriesOptionList (optionOrder.getAccessoriesOptionList ());


            // 项目分类CD--配料
            order.setItemCategoryCd (ResourcesUtil.getConfig ("item_type_cd-30"));
            // 根据订单查询设计信息
            List <DesignOption> optionList3 = this.orderService.findDesignOptionMaterialByOrderId (order);
            // 前台显示用
            model.addAttribute ("optionList3", optionList3);
            optionOrder = resolveDesignInfo (order, optionList3, ResourcesUtil.getConfig ("item_type_cd-30"));
            order.setMixedIngredientsItemList (optionOrder.getMixedIngredientsItemList ());
            order.setMixedIngredientsOptionList (optionOrder.getMixedIngredientsOptionList ());

            // 项目分类CD--刺绣
            order.setItemCategoryCd (ResourcesUtil.getConfig ("item_type_cd-40"));
            // 根据订单查询设计信息
            List <DesignOption> optionList4 = this.orderService.findDesignOptionByOrderId (order);
            // 前台显示用
            model.addAttribute ("optionList4", optionList4);
            optionOrder = resolveDesignInfo (order, optionList4, ResourcesUtil.getConfig ("item_type_cd-40"));
            order.setEmbroideryItemList (optionOrder.getEmbroideryItemList ());
            order.setEmbroideryOptionList (optionOrder.getEmbroideryOptionList ());


            // 项目分类CD--标牌定制
            order.setItemCategoryCd (ResourcesUtil.getConfig ("item_type_cd-50"));
            // 根据订单查询设计信息
            List <DesignOption> optionList5 = this.orderService.findDesignOptionByOrderId (order);
            // 前台显示用
            model.addAttribute ("optionList5", optionList5);
            optionOrder = resolveDesignInfo (order, optionList5, ResourcesUtil.getConfig ("item_type_cd-50"));
            order.setSignItemList (optionOrder.getSignItemList ());
            order.setSignOptionList (optionOrder.getSignOptionList ());


            // 算出项目钱
//            order = orderService.mergeOptionItems(order);
//            model.addAttribute("order", order);


            // 返回URL
            return "modules/order/orderShow";


        } catch (Exception e) {
            // 记录日志
            logger.error (e.getMessage (), e);
            return null;
        }

    }

    /**
     * 分解款式信息
     *
     * @param order
     * @param optionList
     * @param styleName
     * @return
     */
    private Order resolveDesignInfo(Order order, List <DesignOption> optionList, String styleName) {
        if (optionList == null) {
            return order;
        }

        if (optionList.size () == 0) {
            return order;
        }
        // 项目值
        String[] itemValue = new String[optionList.size ()];
        // 选项值
        String[] optionValue = new String[optionList.size ()];

        for (int i = 0; i < optionList.size (); i++) {
            itemValue[i] = optionList.get (i).getItemCD () + "-" + optionList.get (i).getItemValue ();
            if (optionList.get (i).getItemValue ().equals (ResourcesUtil.getConfig ("shirt_con"))) {
                optionValue[i] = optionList.get (i).getOptionValue ();
            } else {
                optionValue[i] = optionList.get (i).getItemValue () + "-" + optionList.get (i).getOptionValue ();
            }

        }


        // 款式
        if (styleName.equals (ResourcesUtil.getConfig ("item_type_cd-10"))) {

            order.setStyleItemList (itemValue);
            order.setStyleOptionList (optionValue);

        }

        // 辅料
        if (styleName.equals (ResourcesUtil.getConfig ("item_type_cd-20"))) {

            order.setAccessoriesItemList (itemValue);
            order.setAccessoriesOptionList (optionValue);

        }

        // 配料
        if (styleName.equals (ResourcesUtil.getConfig ("item_type_cd-30"))) {

            order.setMixedIngredientsItemList (itemValue);
            order.setMixedIngredientsOptionList (optionValue);

        }

        // 刺绣
        if (styleName.equals (ResourcesUtil.getConfig ("item_type_cd-40"))) {

            order.setEmbroideryItemList (itemValue);
            order.setEmbroideryOptionList (optionValue);

        }

        // 标牌
        if (styleName.equals (ResourcesUtil.getConfig ("item_type_cd-50"))) {

            order.setSignItemList (itemValue);
            order.setSignOptionList (optionValue);

        }

        return order;

    }

    /**
     * 根据面料ID查找面料信息
     *
     * @param order
     * @param model
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"searchInfoByMaterialId"})
    public String searchInfoByMaterialId(Order order, Model model) {

        try {

            // 店铺ID
            order.setShopId (UserUtils.getUser ().getShop ().getId ());

            // 面料信息
            model.addAttribute ("materialItem", this.orderService.searchInfoByMaterialId (order));

            if (order.getUpdateFlag ().equals ("0")) {
                return "modules/order/orderCreate";

            } else {
                return "modules/order/orderCreateModify";
            }


        } catch (Exception e) {

            // 记录日志
            logger.error (e.getMessage (), e);
            return null;

        }
    }

    /**
     * 导出定制项目单耗
     *
     * @param response
     * @param styleOptionEntity
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "exportFile")
    public String exportFile(StyleOptionEntity styleOptionEntity, HttpServletResponse response) {
        try {
            SXSSFWorkbook wb = new SXSSFWorkbook ();
            StyleOptionEntity styleOption = orderService.makeOptionList (styleOptionEntity, "面料品号");

            // custom_msg04 :定制项目
            new ExportExcel ("定制单耗", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionList ());
            new ExportExcel ("原料", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionFabricList ());
            new ExportExcel ("扣", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionSBUList ());
            new ExportExcel ("商标", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionLPList ());
            new ExportExcel ("洗涤标", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionCALBList ());
            new ExportExcel ("小号", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionSIZELBList ());
            new ExportExcel ("辅料", wb, "定制项目", StyleOptionEntity.class, 2).setDataList (styleOption.getStyleOptionSCONList ());
            sky = wb;
            return renderString (response,"true");
        } catch (Exception e) {
            // 记录日志
            logger.error (e.getMessage (), e);
        }

        // 提示错误信息
        return renderString (response, AjaxDone.error (getText ("System_error_please_contact_your_administrator")));

    }
    
    /**
     * Excel下载
     *
     * @param response
     * @return
     * @throws Exception
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"makeExportFile"})
    public void makeExportFile(String contractNo,HttpServletResponse response, HttpServletRequest request)
            throws Exception {
    	String fileName = contractNo + "定制单耗表.xlsx";
        response.reset ();
        response.setContentType ("application/octet-stream; charset=utf-8");
        response.setCharacterEncoding ("UTF-8");
        response.setHeader ("Content-Disposition", "attachment; filename=" + new String (fileName.getBytes (), "ISO-8859-1"));
        sky.write (response.getOutputStream ());
    }

    /**
     * 导出走货明细
     *
     * @param response
     * @param transportGoodsDetail
     * @return
     */
    @RequiresPermissions("customization:order:edit")
    @RequestMapping(value = "exportTransportGoodsDetail")
    public String exportTransportGoodsDetail(TransportGoodsDetail transportGoodsDetail, HttpServletResponse response, HttpSession session) {
        //Map<Object, Object> listMap = new HashMap<Object, Object>();
        try {
            transportGoodsDetail.setOrderNo (session.getAttribute ("orderNO").toString ());
            transportGoodsDetail.setShirtSgd (session.getAttribute ("shirtSgd").toString ());
            transportGoodsDetail.setBeginDate (session.getAttribute ("beginDate").toString ());
            transportGoodsDetail.setEndDate (session.getAttribute ("endDate").toString ());
            transportGoodsDetail.setOrderStatusCD (session.getAttribute ("orderStatusCD").toString ());
            transportGoodsDetail.setStyleNoFrom (session.getAttribute ("styleNoFrom").toString ());
            transportGoodsDetail.setStyleNoTo (session.getAttribute ("styleNoTo").toString ());
            String fileName = getText ("export_transportGoodsDetail");
            List <TransportGoodsDetail> list = orderService.exportTGDetail (transportGoodsDetail);
            new ExportExcel (getText ("export_trans_msg01"), TransportGoodsDetail.class, 2).setDataList (list).write (response, fileName).dispose ();
            //listMap.put("list", list);
            //listMap.put("flg", true);
            return null;
        } catch (Exception e) {
            // 记录日志
            logger.error (e.getMessage (), e);
        }
        //listMap.put("flg", "false");
        // 提示错误信息
        return renderString (response, AjaxDone.error (getText ("System_error_please_contact_your_administrator")));

    }

    /**
     * 导出走货明细
     *
     * @param response
     * @param response
     * @return
     * @throws IOException
     */
    @RequiresPermissions("customization:order:edit")
    @RequestMapping(value = "backstage")
    public String backstage(HttpServletResponse response) throws IOException {
        // custom_msg04 :定制项目
        /*try {
            String fileName = getText("export_transportGoodsDetail");
            
        	new ExportExcel(getText("export_trans_msg01"), TransportGoodsDetail.class, 2).setDataList(tDetailsList).write(response, fileName).dispose();
            return null;
        } catch (Exception e) {
            // 记录日志
            logger.error(e.getMessage(), e);
        }
        // 提示错误信息
        return renderString(response,AjaxDone.error(getText("System_error_please_contact_your_administrator")));*/
        return renderString (response, "cloud");
    }

    /**
     * excel上传画面迁移
     *
     * @return
     */
    @RequestMapping(value = {"uploadExcelFile"})
    public String popupUploadExcelFile(Model model) {

        model.addAttribute ("customList", orderService.findCustomList ());
        model.addAttribute ("imageName", "orderList");
        return "modules/order/uploadOrderExcelFile";
    }
    
    /**
     * excel上传画面迁移
     *
     * @return
     */
    @RequestMapping(value = {"excelEnchaseInfo"})
    public String excelEnchaseInfo(Model model) {

        return "modules/order/uploadFileEnchaseInfo";
    }

    /**
     * 订单费用详情
     *
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"costDetail"})
    public String costDetail(Order order, Model model) {
        List <StyleCostEntity> styleCostList = orderService.findStyleCostList (order.getStyleId ());
        model.addAttribute ("styleCostList", styleCostList);
        return "modules/order/orderCostDetail";
    }

    /**
     * 联动返回款式
     *
     * @param file
     * @param response
     * @return
     * @throws Exception 
     */
    @RequestMapping(value = "insertExcelData", method = RequestMethod.POST)
    @ResponseBody
    public String insertExcelData(MultipartFile file, HttpServletResponse response,HttpServletRequest request,
    		String customName,Long venderID,String orderType,String orderDate) throws Exception {
        String oldFlg = "false";
        stopFlag = false;
        completeFlag = false;
        importOrder = Thread.currentThread();
        new Thread(){
			public void run() {
                while (true) {
                	logger.info("//--------还在循环里--------//");
                	System.out.println("//--------还在循环里--------//");
                    try {
						Thread.sleep(2000);
						if (stopFlag) {
							importOrder.stop();
							logger.info("//--------------订单导入已终止---------------//");
							System.out.println("//--------------订单导入已终止---------------//");
							break;
						}
						if (completeFlag) {
							logger.info("//--------------订单导入已完成---------------//");
							System.out.println("//--------------订单导入已完成---------------//");
							break;
						}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						logger.error("已终止", e);
					}
                }
            }
        }.start();
        try {
            ImportExcel ei = new ImportExcel (file, 1, 0);
            SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
            Workbook workbook = ei.wb;
            Sheet st = workbook.getSheetAt (0);
            int rowmun = st.getPhysicalNumberOfRows ();
            String codeFormat = "%02d";
            // 日期初期化
            Date dateCell = new Date ();
            String cellStr;
            // 订单实体类
            Order order1 = new Order ();
            //
            StyleDesignHistoryEntity cloudEntity = new StyleDesignHistoryEntity();
            List<StyleDesignHistoryEntity> cloudList = new ArrayList<>();
            /**
             * excel各行计数器
             */
            int row_Yun = 41;
            int row_0 = 0;
            int row_1 = 1;
            int row_2 = 2;
            int row_3 = 3;
            int row_4 = 4;
            int row_6 = 6;
            int row_7 = 7;
            int row_8 = 8;
            int row_9 = 9;
            int row_10 = 10;
            int row_11 = 11;
            int row_12 = 12;
            int row_13 = 13;
            int row_14 = 14;
            int row_15 = 15;
            int row_16 = 16;
            int row_17 = 17;
            int row_18 = 18;
            int row_19 = 19;
            int row_20 = 20;
            int row_21 = 21;
            int row_22 = 22;
            int row_23 = 23;
            int row_24 = 24;
            int row_25 = 25;
            int row_26 = 26;
            int row_27 = 27;
            int row_28 = 28;
            int row_29 = 29;
            int row_30 = 30;
            int row_31 = 31;
            int row_32 = 32;
            int row_33 = 33;
            int row_34 = 34;
            int row_35 = 35;
            int row_36 = 36;
            int row_37 = 37;
            int row_38 = 38;
            int row_39 = 39;
            int row_40 = 40;
            // 款式类别判断（衬衫or西服）
            boolean orderPartsFlg = false;
            Date shipDate4M = SequenceUtil.getShipTime("4M");
            Date shipDate4H = SequenceUtil.getShipTime("4H");
            int count = 0;
            //衬衫规格尺码
            String styleGroupNum = "";
            //订单号
            String orderNo = "";
            //袖开祺
            String ssvStr = "";
            //袖头
            String scuStr = "";
            //面料号前半部分（供衬布颜色使用）
            String materialHeadCode = "";
            int orderNum = 1;
            int orderNumSum = 0;
            String bigOrder = "flase";
            for (int i = 0; i < rowmun; i++) {
                if (count == 0 && row_0 < rowmun) {
                	if ((st.getRow (row_0) == null)||(st.getRow (row_0) != null && "".equals(getCellValue (st.getRow (row_0).getCell (1)).trim()))) {
    					break;
    				}
                    // 订单号
                    cellStr = getCellValue (st.getRow (row_0).getCell (1));
                    orderNo = cellStr;
					cloudEntity.setOrderNo(cellStr.trim());
                    // 加急标识CD
                    cellStr = getCellValue (st.getRow (row_0).getCell (4));
                    if (valuechange (cellStr).matches ("No")) {
                        cellStr = "ORDER_FLAG-normal_10";
                    } else {
                        cellStr = "ORDER_FLAG-express_20";
                    }
                    cloudEntity.setUrgentOrder(cellStr);
                    // 款式类别
                    cellStr = getCellValue (st.getRow (row_0).getCell (7));
                    if (cellStr.matches (REF)) {
                        cellStr = ResourcesUtil.getConfig ("style_category_excel");
                        orderPartsFlg = true;
                    }
                    // 日本大货
                    if (ResourcesUtil.getConfig("order_type-type_50").equals(orderType)) {
                    	// 西服
						if ("SUIT".equals(cellStr.trim().toUpperCase())) {
							cellStr = "STYLE_CATEGORY-SUIT";
						// 裙子
						}else if ("SKIRT".equals(cellStr.trim().toUpperCase())) {
							cellStr = "STYLE_CATEGORY-SKIRT";
						// 裤子
						}else if ("PANTS".equals(cellStr.trim().toUpperCase())) {
							cellStr = "STYLE_CATEGORY-PANTS";
						// 衬衫
						}else if ("SHIRTS".equals(cellStr.trim().toUpperCase())) {
							cellStr = "STYLE_CATEGORY-SHIRT";
						}
						orderPartsFlg = true;
					// 荷兰小样
					}else if(ResourcesUtil.getConfig("order_type-type_60").equals(orderType)){
						// 小样
						if ("SAMPLE".equals(cellStr.trim().toUpperCase())) {
							cellStr = "STYLE_CATEGORY-SAMPLE";
						}
						orderPartsFlg = true;
					}
                    cloudEntity.setOrderParts(cellStr);
                    row_0 = row_0 + row_Yun;
                    count++;
                } else if (count == 1 && row_1 < rowmun) {
                    // 订单日期
                    if (st.getRow (row_1).getCell (1) != null && getCellValue (st.getRow (row_1).getCell (1)) != "") {
                        order1.setOrderStatusCD ("111111");
                        cellStr = sdf.format (HSSFDateUtil.getJavaDate (st.getRow (row_1).getCell (1).getNumericCellValue ()));
                        dateCell = sdf.parse (cellStr);
                    } else {
                        dateCell = null;
                    }
                    cloudEntity.setOrderDate(dateCell);
                    // 量体样衣区分
                    cellStr = getCellValue (st.getRow (row_1).getCell (4));
                    if (valuechange (cellStr).matches ("No")) {
                        cellStr = "No";
                    }
                    cloudEntity.setTryonOrder(cellStr);
                    // 款式面料编号
                    cellStr = getCellValue (st.getRow (row_1).getCell (7));
                    materialHeadCode = cellStr.split("/")[0].trim();
                    //Material material = orderService.getMaterialInfo (cellStr.trim ());
                    cloudEntity.setFabricCode(materialHeadCode);
                    row_1 = row_Yun + row_1;
                    count++;
                } else if (count == 2 && row_2 < rowmun) {
                    // 客户名称
                    cellStr = getCellValue (st.getRow (row_2).getCell (1));
                    cloudEntity.setCustomerName(valuechange (cellStr));
                    // 特殊订单区分
                    cellStr = getCellValue (st.getRow (row_2).getCell (4));
                    cloudEntity.setSpecialOrder(valuechange (cellStr));;
                    // 面料成分
                    cellStr = getCellValue (st.getRow (row_2).getCell (7));
                    cloudEntity.setFabricComposition(cellStr.trim ());
                    row_2 = row_Yun + row_2;
                    count++;
                } else if (count == 3 && row_3 < rowmun) {
                    // 店名
                    cellStr = getCellValue (st.getRow (row_3).getCell (1));
                    cloudEntity.setShopName(valuechange (cellStr));
                    // 发货目的地
                    cellStr = getCellValue (st.getRow (row_3).getCell (4));
                    cloudEntity.setShippingDestination(valuechange (cellStr));
                    row_3 = row_Yun + row_3;
                    count++;
                } else if (count == 4 && row_4 < rowmun) {
                    // 船期
                	cellStr = getCellValue (st.getRow (row_6).getCell (4));
                	if ("4M".equals (valuechange (cellStr).trim ()) || "BM".equals (valuechange (cellStr).replace(".", "").trim ())) {
                        cloudEntity.setShipmentDate(shipDate4M);
					}else if ("4H".equals (valuechange (cellStr).trim ())) {
	                    cloudEntity.setShipmentDate(shipDate4H);
					}
                	// 日本大货 和 荷兰小样
                    if (ResourcesUtil.getConfig("order_type-type_50").equals(orderType)
                    		|| ResourcesUtil.getConfig("order_type-type_60").equals(orderType)) {
                    	cellStr = sdf.format (HSSFDateUtil.getJavaDate (st.getRow (row_4).getCell (1).getNumericCellValue ()));
                    	dateCell = sdf.parse (cellStr);
                    	cloudEntity.setShipmentDate(dateCell);
                    }
                    // 款式中文名
                    cellStr = getCellValue (st.getRow (row_4).getCell (3));
                    cloudEntity.setStyleNameCn(cellStr.trim());
                    scuStr = valuechange (getCellValue (st.getRow (row_10).getCell (4)));
                    ssvStr = valuechange (getCellValue (st.getRow (row_11).getCell (4)));
                    if (("".equals(scuStr)||"-".equals(scuStr)||"--".equals(scuStr))&&("".equals(ssvStr)||"-".equals(ssvStr)||"--".equals(ssvStr))) {
	                    cloudEntity.setSleeveFlag(1);
					}else {
	                    cloudEntity.setSleeveFlag(0);
					}
                    // 订单数量
                    cellStr = getCellValue (st.getRow (row_4).getCell (7)).trim();
                    if (!"".equals(cellStr)) {
                		orderNum = (int)Double.parseDouble(cellStr);
                		bigOrder = "true";
                		cloudEntity.setOrderStatusFlag("bigOrder");
    				}
                    row_4 = row_Yun + row_4;
                    count = count + 2;
                } else if (count == 6 && row_6 < rowmun) {
                    // 款式制作工艺
                    cellStr = getCellValue (st.getRow (row_6).getCell (4));
                    if (!"".equals (cellStr)) {
                        cloudEntity.setModelSma(valuechange (cellStr).replace(".", "").trim());
                    }
                    // 缝制线
                    cellStr = getCellValue (st.getRow (row_6).getCell (7));
                    if (orderPartsFlg && !"".equals (cellStr)) {
                    	cloudEntity.setTrimThdno(valuechange (cellStr).trim ());
                    }
                    row_6 = row_6 + row_Yun;
                    count++;
                } else if (count == 7 && row_7 < rowmun) {
                    // 款式版型
                    cellStr = getCellValue (st.getRow (row_7).getCell (4));
                    cloudEntity.setModelShm(valuechange (cellStr).trim ());
                    // 线号
                    cellStr = getCellValue (st.getRow (row_7).getCell (7));
                    cloudEntity.setTrimSgd(valuechange(cellStr));
                    row_7 = row_7 + row_Yun;
                    count++;
                } else if (count == 8 && row_8 < rowmun) {
                    if (orderPartsFlg) {
                        // 袖子
                        cellStr = getCellValue (st.getRow (row_8).getCell (4));
                        cloudEntity.setModelSsl(valuechange (cellStr));
                        // 扣
                        cellStr = getCellValue (st.getRow (row_8).getCell (7));
                        cloudEntity.setTrimSbu(cellStr.trim());
                    }
                    row_8 = row_8 + row_Yun;
                    count++;
                } else if (count == 9 && row_9 < rowmun) {
                    if (orderPartsFlg) {
                        // 领子
                        cellStr = getCellValue (st.getRow (row_9).getCell (4));
                        cloudEntity.setModelSco(valuechange (cellStr));
                        // 扣眼颜色
                        cellStr = getCellValue (st.getRow (row_9).getCell (7));
                        cloudEntity.setTrimSbh(valuechange (cellStr));
                    }
                    row_9 = row_9 + row_Yun;
                    count++;
                } else if (count == 10 && row_10 < rowmun) {
                    if (orderPartsFlg) {
                        // 袖头
                        cellStr = getCellValue (st.getRow (row_10).getCell (4));
                        cloudEntity.setModelScu(valuechange (cellStr).replace(".", ""));
                        // 订扣
                        cellStr = getCellValue (st.getRow (row_10).getCell (7));
                        cloudEntity.setTrimSat(valuechange (cellStr));
                    }
                    row_10 = row_10 + row_Yun;
                    count++;
                } else if (count == 11 && row_11 < rowmun) {
                    if (orderPartsFlg) {
                        // 袖开祺
                        cellStr = getCellValue (st.getRow (row_11).getCell (4));
                        cloudEntity.setModelSsv(valuechange (cellStr));
                        // 订扣线颜色
                        cellStr = getCellValue (st.getRow (row_11).getCell (7));
                        cloudEntity.setTrimSbt(valuechange (cellStr));
                    }
                    row_11 = row_11 + row_Yun;
                    count++;
                } else if (count == 12 && row_12 < rowmun) {
                    if (orderPartsFlg) {
                        // 衬布
                        cellStr = getCellValue (st.getRow (row_12).getCell (4));
                        cloudEntity.setModelSsk(valuechange (cellStr));
                        // 领子，袖头配色线
                        cellStr = getCellValue (st.getRow (row_12).getCell (7));
                        cloudEntity.setTrimSts(valuechange (cellStr));
                    }
                    row_12 = row_12 + row_Yun;
                    count++;
                } else if (count == 13 && row_13 < rowmun) {
                    if (orderPartsFlg) {
                        // 领插签
                        cellStr = getCellValue (st.getRow (row_13).getCell (4));
                        cloudEntity.setModelSbo(valuechange (cellStr));
                        // 台领下夹牙绳
                        cellStr = getCellValue (st.getRow (row_13).getCell (7));
                        cloudEntity.setTrimSbi(valuechange (cellStr));
                    }
                    row_13 = row_13 + row_Yun;
                    count++;
                } else if (count == 14 && row_14 < rowmun) {
                    if (orderPartsFlg) {
                        // 前立
                        cellStr = getCellValue (st.getRow (row_14).getCell (4));
                        cloudEntity.setModelSfp(valuechange (cellStr));
                    }
                    row_14 = row_14 + row_Yun;
                    count++;
                } else if (count == 15 && row_15 < rowmun) {
                    if (orderPartsFlg) {
                        // 胸兜
                        cellStr = getCellValue (st.getRow (row_15).getCell (4));
                        cloudEntity.setModelSbp(valuechange (cellStr));
                    }
                    row_15 = row_15 + row_Yun;
                    count++;
                } else if (count == 16 && row_16 < rowmun) {
                    if (orderPartsFlg) {
                        // 后背款式
                        cellStr = getCellValue (st.getRow (row_16).getCell (4));
                        cloudEntity.setModelSba(valuechange (cellStr));
                        // 水洗要求
                        cellStr = getCellValue (st.getRow (row_16).getCell (7));
                        cloudEntity.setModelWash(valuechange (cellStr));
                    }
                    row_16 = row_16 + row_Yun;
                    count++;
                } else if (count == 17 && row_17 < rowmun) {
                    if (orderPartsFlg) {
                        // 领子，袖口明线
                        cellStr = getCellValue (st.getRow (row_17).getCell (4));
                        cloudEntity.setModelSst(valuechange (cellStr));
                        // 包装方法
                        cellStr = getCellValue (st.getRow (row_17).getCell (7));
                        cloudEntity.setModelSpck(valuechange (cellStr));
                    }
                    row_17 = row_17 + row_Yun;
                    count++;
                } else if (count == 18 && row_18 < rowmun) {
                    if (orderPartsFlg) {
                        // 手绢
                        cellStr = getCellValue (st.getRow (row_18).getCell (4));
                        cloudEntity.setModelSpo(valuechange (cellStr));
                        // Ribbon
                        cellStr = getCellValue (st.getRow (row_18).getCell (7));
                        cloudEntity.setModelRibb(cellStr);
                    }
                    row_18 = row_18 + row_Yun;
                    count++;
                } else if (count == 19 && row_19 < rowmun) {
                    if (orderPartsFlg) {
                        // 后省
                        cellStr = getCellValue (st.getRow (row_19).getCell (4));
                        cloudEntity.setModelSbd(valuechange (cellStr));
                        // 日本大货 和 荷兰小样
                        if (ResourcesUtil.getConfig("order_type-type_50").equals(orderType)
                        		|| ResourcesUtil.getConfig("order_type-type_60").equals(orderType)) {
                        	// 价格
                        	cellStr = getCellValue (st.getRow (row_19).getCell (7));
                        	cloudEntity.setPrice(valuechange (cellStr));
                        }
                    }
                    
                    row_19 = row_19 + row_Yun;
                    count++;
                } else if (count == 20 && row_20 < rowmun) {
                    if (orderPartsFlg) {
                        // 过肩
                        cellStr = getCellValue (st.getRow (row_20).getCell (4));
                        cloudEntity.setModelSbj(valuechange (cellStr));
                        // 日本大货 和 荷兰小样
                        if (ResourcesUtil.getConfig("order_type-type_50").equals(orderType)
                        		|| ResourcesUtil.getConfig("order_type-type_60").equals(orderType)) {
                        	// 实际交付日期
                        	cellStr = sdf.format (HSSFDateUtil.getJavaDate (st.getRow (row_20).getCell (7).getNumericCellValue ()));
                        	dateCell = sdf.parse (cellStr);
                        	cloudEntity.setRealDate(dateCell);
                        }
                    }
                    row_20 = row_20 + row_Yun;
                    count++;
                } else if (count == 21 && row_21 < rowmun) {
                    if (orderPartsFlg) {
                        // 底摆款式
                        cellStr = getCellValue (st.getRow (row_21).getCell (4));
                        cloudEntity.setModelSbs(valuechange (cellStr));
                    }
                    row_21 = row_21 + row_Yun;
                    count++;
                } else if (count == 22 && row_22 < rowmun) {
                    if (orderPartsFlg) {
                        // 尺码
                        cellStr = getCellValue (st.getRow (row_22).getCell (0));
                        styleGroupNum = cellStr.replaceAll ("[^0-9]", "");
                        cloudEntity.setShirtSize(styleGroupNum.trim());
                    }
                    row_22 = row_22 + row_Yun;
                    count++;
                } else if (count == 23 && row_23 < rowmun) {
                    if (orderPartsFlg) {
                        // 胸围
                        cellStr = getCellValue (st.getRow (row_23).getCell (1));
                        cloudEntity.setSize12che(cellStr.trim());
                        // 小号
                        cellStr = getCellValue (st.getRow (row_23).getCell (4));
                        cloudEntity.setLablSize(cellStr.trim());
                        // 台领里配料
                        cellStr = getCellValue (st.getRow (row_23).getCell (7));
                        cloudEntity.setContSc1(valuechange(cellStr).trim());
                    }
                    row_23 = row_23 + row_Yun;
                    count++;
                } else if (count == 24 && row_24 < rowmun) {
                    if (orderPartsFlg) {
                        // 腰围
                        cellStr = getCellValue (st.getRow (row_24).getCell (1));
                        cloudEntity.setSize12wai(cellStr.trim());
                        // 小号种类
                        cellStr = getCellValue (st.getRow (row_24).getCell (4));
                        cloudEntity.setLablSizeType(cellStr.trim());
                        //  羽领，台领配料
                        cellStr = getCellValue (st.getRow (row_24).getCell (7));
                        cloudEntity.setContSc2(valuechange (cellStr).trim());
                    }
                    row_24 = row_24 + row_Yun;
                    count++;
                } else if (count == 25 && row_25 < rowmun) {
                    if (orderPartsFlg) {
                        //  1/2 底摆
                        cellStr = getCellValue (st.getRow (row_25).getCell (1));
                        cloudEntity.setSize12hip(cellStr.trim());
                        // 三角布
                        //cellStr = getCellValue (st.getRow (row_25).getCell (4));
                        // 后领中订商标
                        cellStr = getCellValue (st.getRow (row_25).getCell (4));
                        cloudEntity.setLablLp1(cellStr.trim());
                        //cloudEntity.setLablLp2(cellStr.trim());
                        //  袖头里配料
                        cellStr = getCellValue (st.getRow (row_25).getCell (7));
                        cloudEntity.setContSc3(valuechange (cellStr).trim());
                    }
                    row_25 = row_25 + row_Yun;
                    count++;
                } else if (count == 26 && row_26 < rowmun) {
                    if (orderPartsFlg) {
                        // 肩宽
                        cellStr = getCellValue (st.getRow (row_26).getCell (1));
                        cloudEntity.setSizeYok(cellStr.trim());
                        // 上前立里侧订商标
                        cellStr = getCellValue (st.getRow (row_26).getCell (4));
                        cloudEntity.setLablLp3(cellStr.trim());
                        //  袖头配料
                        cellStr = getCellValue (st.getRow (row_26).getCell (7));
                        cloudEntity.setContSc4(valuechange (cellStr).trim());
                    }
                    row_26 = row_26 + row_Yun;
                    count++;
                } else if (count == 27 && row_27 < rowmun) {
                    if (orderPartsFlg) {
                        // 后衣长
                        cellStr = getCellValue (st.getRow (row_27).getCell (1));
                        cloudEntity.setSizeLen(cellStr.trim());
                        // 下前立里侧订商标
                        cellStr = getCellValue (st.getRow (row_27).getCell (4));
                        cloudEntity.setLablLp4(cellStr.trim());
                        //  台领配料
                        cellStr = getCellValue (st.getRow (row_27).getCell (7));
                        cloudEntity.setContSc5(valuechange (cellStr).trim());
                    }
                    row_27 = row_27 + row_Yun;
                    count++;
                } else if (count == 28 && row_28 < rowmun) {
                    if (orderPartsFlg) {
                        // 领围
                        cellStr = getCellValue (st.getRow (row_28).getCell (1));
                        cloudEntity.setSizeCol(cellStr.trim());
                        // 大布订商标
                        cellStr = getCellValue (st.getRow (row_28).getCell (4));
                        cloudEntity.setLablLp5(cellStr.trim());
                        //  上前立表配料
                        cellStr = getCellValue (st.getRow (row_28).getCell (7));
                        cloudEntity.setContSc6(valuechange (cellStr).trim());
                    }
                    row_28 = row_28 + row_Yun;
                    count++;
                } else if (count == 29 && row_29 < rowmun) {
                    if (orderPartsFlg) {
                        // 大臂围
                        cellStr = getCellValue (st.getRow (row_29).getCell (1));
                        cloudEntity.setSizeUam(cellStr.trim());
                        // 后领缝商标
                        cellStr = getCellValue (st.getRow (row_29).getCell (4));
                        cloudEntity.setLablLp6(cellStr.trim());
                        //  下前立配料
                        cellStr = getCellValue (st.getRow (row_29).getCell (7));
                        cloudEntity.setContSc7(valuechange (cellStr).trim());
                    }
                    row_29 = row_29 + row_Yun;
                    count++;
                } else if (count == 30 && row_30 < rowmun) {
                    if (orderPartsFlg) {
                        // 左小臂围
                        cellStr = getCellValue (st.getRow (row_30).getCell (1));
                        cloudEntity.setSizeFal(cellStr.trim());
                        // 吊牌
                        cellStr = getCellValue (st.getRow (row_30).getCell (4));
                        cloudEntity.setLablHas(cellStr.trim());
                        //  袖补强布配料
                        cellStr = getCellValue (st.getRow (row_30).getCell (7));
                        cloudEntity.setContSc8(valuechange (cellStr).trim());
                    }
                    row_30 = row_30 + row_Yun;
                    count++;
                } else if (count == 31 && row_31 < rowmun) {
                    if (orderPartsFlg) {
                        // 右小臂围
                        cellStr = getCellValue (st.getRow (row_31).getCell (1));
                        cloudEntity.setSizeFar(cellStr.trim());
                        // 洗涤成分
                        cellStr = getCellValue (st.getRow (row_31).getCell (4));
                        cloudEntity.setLablCl(cellStr.trim());
                        //  手绢配料
                        cellStr = getCellValue (st.getRow (row_31).getCell (7));
                        cloudEntity.setContSc9(valuechange (cellStr).trim());
                    }
                    row_31 = row_31 + row_Yun;
                    count++;
                } else if (count == 32 && row_32 < rowmun) {
                    if (orderPartsFlg) {
                        // 左袖头围缩小
                        cellStr = getCellValue (st.getRow (row_32).getCell (1));
                        cloudEntity.setSizeScl(cellStr.trim());
                        // Care label type
                        cellStr = getCellValue (st.getRow (row_32).getCell (4));
                        cloudEntity.setLablClt(cellStr.trim());
                        //  大布配料
                        cellStr = getCellValue (st.getRow (row_32).getCell (7));
                        cloudEntity.setContSc0(valuechange (cellStr).trim());
                    }
                    row_32 = row_32 + row_Yun;
                    count++;
                } else if (count == 33 && row_33 < rowmun) {
                    if (orderPartsFlg) {
                        // 右袖头围缩小
                        cellStr = getCellValue (st.getRow (row_33).getCell (1));
                        cloudEntity.setSizeScr(cellStr.trim());
                        // 产地标
                        cellStr = getCellValue (st.getRow (row_33).getCell (4));
                        cloudEntity.setLablCoo(cellStr.trim());
                    }
                    row_33 = row_33 + row_Yun;
                    count++;
                } else if (count == 34 && row_34 < rowmun) {
                    if (orderPartsFlg) {
                        // 左袖头围左
                        cellStr = getCellValue (st.getRow (row_34).getCell (1));
                        cloudEntity.setSizeCll(cellStr.trim());
                    }
                    row_34 = row_34 + row_Yun;
                    count++;
                } else if (count == 35 && row_35 < rowmun) {
                    if (orderPartsFlg) {
                        // 右袖头围右
                        cellStr = getCellValue (st.getRow (row_35).getCell (1));
                        cloudEntity.setSizeClr(cellStr.trim());
                        // 左肩底
                        cellStr = getCellValue (st.getRow (row_35).getCell (4));
                        cloudEntity.setSizeLsl(cellStr.trim());
                        // 刺绣内容
                        cellStr = getCellValue (st.getRow (row_35).getCell (7));
                        cloudEntity.setEmbrText(cellStr.trim().replace(",", "&#44"));
                    }
                    row_35 = row_35 + row_Yun;
                    count++;
                } else if (count == 36 && row_36 < rowmun) {
                    if (orderPartsFlg) {
                        // 左袖短
                        cellStr = getCellValue (st.getRow (row_36).getCell (1));
                        cloudEntity.setSizeSsl(cellStr.trim());
                        // 右肩底
                        cellStr = getCellValue (st.getRow (row_36).getCell (4));
                        cloudEntity.setSizeLsr(cellStr.trim());
                        // 刺绣颜色
                        cellStr = getCellValue (st.getRow (row_36).getCell (7));
                        cloudEntity.setEmbrSmc(valuechangeSMC (cellStr));
                    }
                    row_36 = row_36 + row_Yun;
                    count++;
                } else if (count == 37 && row_37 < rowmun) {
                    if (orderPartsFlg) {
                        // 右袖短
                        cellStr = getCellValue (st.getRow (row_37).getCell (1));
                        cloudEntity.setSizeSsr(cellStr.trim());
                        // 前立扣位
                        cellStr = getCellValue (st.getRow (row_37).getCell (4));
                        cloudEntity.setSizeRbh(cellStr.trim());
                        // 字体
                        cellStr = getCellValue (st.getRow (row_37).getCell (7));
                        cloudEntity.setEmbrSmo(valuechange (cellStr));
                    }
                    row_37 = row_37 + row_Yun;
                    count++;
                } else if (count == 38 && row_38 < rowmun) {
                    if (orderPartsFlg) {
                    	
                        // 左袖长左
                        cellStr = getCellValue (st.getRow (row_38).getCell (1));
                        cloudEntity.setSizeSll(cellStr.trim());
                        // 前立扣数
                        cellStr = getCellValue (st.getRow (row_38).getCell (4));
                        cloudEntity.setSizeBof(cellStr.trim());
                        // 刺绣位置
                        cellStr = getCellValue (st.getRow (row_38).getCell (7));
                        cloudEntity.setEmbrSmp(valuechange (cellStr).replace (" ", ""));
                    }
                    row_38 = row_38 + row_Yun;
                    count++;
                } else if (count == 39 && row_39 < rowmun) {
                    if (orderPartsFlg) {
                        // 右袖长右
                        cellStr = getCellValue (st.getRow (row_39).getCell (1));
                        cloudEntity.setSizeSlr(cellStr.trim());
                        // 刺绣大小
                        cellStr = getCellValue (st.getRow (row_39).getCell (7));
                        cloudEntity.setEmbrSms(valuechange (cellStr).replace (" ", ""));
                    }
                    for (int k = 0; k < orderNum; k++) {
                    	cloudList.add(cloudEntity);
					}
                    cloudEntity = new StyleDesignHistoryEntity();
                    row_39 = row_39 + row_Yun;
                    count = 0;
                }
	            orderNumSum = orderNumSum + orderNum;
            }
            if ("true".equals(bigOrder)) {
            	List<StyleDesignHistoryEntity> clist = new  ArrayList<>();
            	for (int j = 0; j < cloudList.size(); j++) {
            		StyleDesignHistoryEntity styleDesignHistoryEntity = cloudList.get(j).clone();
            		styleDesignHistoryEntity.setOrderNo(styleDesignHistoryEntity.getOrderNo() + "-" + String.format(codeFormat, (j + 1)));
            		clist.add(styleDesignHistoryEntity);
            	}
            	cloudList = clist;
			}
            // excel数据导入
            //orderService.insertExcelData (styleList, orderList, orderTempTableEntityList,customName,venderID);
            Long contractId = orderService.insertExcelDataBefore(cloudList, customName, venderID, orderType, "ERP",null,orderDate);
            /*CacheUtils.remove(CACHE_QUALITY_VALUE_MAP_34);
            CacheUtils.remove(CACHE_QUALITY_VALUE_MAP_35);
            CacheUtils.remove(CACHE_QUALITY_VALUE_MAP_36);
            CacheUtils.remove(CACHE_QUALITY_VALUE_MAP_37);*/
            oldFlg = "true";
            //导入成功给指定人员发送邮件
            CustomizationContract contract = orderService.getContractInfo(contractId);
            String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
				        + request.getContextPath() + Global.getAdminPath() + "/customization/order/order?contractID="
				        + contract.getId() + "&contractNo=" + contract.getContractNO() + "&imageFlag=customizationContract&contractDate=" + DateUtils.formatDate(contract.getCreateDate(), "yyyy-MM-dd");
            SendEmailMessage sendEmailMessage = new SendEmailMessage();
            sendEmailMessage.setDataTheme(ResourcesUtil.getConfig("erp_send_mail_theme01"));
            sendEmailMessage.setDataMessage(ResourcesUtil.getConfig("erp_send_mail_textMessage01"));
            sendEmailMessage.setDataXXX01(UserUtils.getUser().getFirstName()+UserUtils.getUser().getLastName());
            sendEmailMessage.setDataXXX02(contract.getContractNO());
            sendEmailMessage.setDataXXX03(contract.getOrderQuantity());
            sendEmailMessage.setDataXURLX(url);
            sendEmailMessage.setDataYYMMDD01(DateUtils.formatDate(contract.getCreateDate(), "yyyy-MM-dd").toString());
            sendEmailMessage.setDataYYMMDD02(DateUtils.formatDate(contract.getContractDeliveryDate(), "yyyy-MM-dd") + " / " + DateUtils.formatDate(contract.getContractDeliveryHDate(), "yyyy-MM-dd"));
            //发送邮件
            UserUtils.sendEmail(sendEmailMessage);
            completeFlag = true;
        } catch (Exception e) {
        	logger.error(e.getMessage(), e);
            oldFlg = e.getMessage();
        }
        return renderString (response, oldFlg);
    }
    
    @RequiresPermissions("customization:order:edit")
    @RequestMapping(value = {"insertTempTable"})
    @ResponseBody
    public String insertTempTable(String customName, HttpServletResponse response) throws Exception {
        String oldFlg = "true";
        try {
            orderService.insertTempTable ("");
            //orderService.insertStyleNo (customName);
        } catch (Exception e) {
        	// 记录日志
            logger.error (e.getMessage (), e);
            oldFlg = "false";
        }
        // ajax返回结果
        return renderString (response, oldFlg);
    }

    /**
     * 导出excel上传画面迁移
     *
     * @return
     */
    @RequestMapping(value = {"exportExcelFile"})
    public String popupExportExcelFile() {
        return "modules/order/exportOrderExcelFile";
    }

    /**
     * 获取费用
     *
     * @param sizeUnitCost
     * @return
     */
    public StyleOptionEntity returnUnitCost(List <StyleOptionEntity> sizeUnitCost, String costStr) {

        for (StyleOptionEntity styleOption : sizeUnitCost) {
            if ((styleOption.getItemCode () + "-" + styleOption.getItemValue ()).equals (costStr)) {

                return styleOption;
            }
        }
        return null;
    }

    /**
     * 获取费用
     *
     * @param designOptionsList
     * @param cellStr
     * @return
     */
    public String returnCost(List <DesignOption> designOptionsList, String cellStr) {

        for (DesignOption designOption : designOptionsList) {
            if (designOption.getItemValue ().equals (cellStr.trim ())) {
                if (designOption.getItemCost () == null || "0.000".equals (designOption.getItemCost ().toString ())) {
                    return "0";
                }
                return designOption.getItemCost ().toString ();
            }
        }
        return "0";
    }

    /**
     * 获取品控信息
     *
     * @param qualityControlList
     * @param itemCode
     * @param itemValue
     * @return
     */
    public String returnQCInfo(List <StyleOptionEntity> qualityControlList, String itemCode, String itemValue) {

        for (StyleOptionEntity styleOption : qualityControlList) {
            if ((styleOption.getItemCode () + "-" + styleOption.getItemValue ()).equals (itemCode + "-" + itemValue)) {
                return styleOption.getQcItem ();
            }
        }
        return "";
    }

    /**
     * 获取SC品控信息
     *
     * @param qualityControlList
     * @param itemCode
     * @return
     */
    public String returnSCQCInfo(List <StyleOptionEntity> qualityControlList, String itemValue) {

        for (StyleOptionEntity styleOption : qualityControlList) {
            if (styleOption.getItemValue ().equals (itemValue)) {
                return styleOption.getQcItem ();
            }
        }
        return "";
    }

    /**
     * 下载导出基础数据模板
     *
     * @param response
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "export/order")
    public String importFileTemplate(HttpServletResponse response) {
        try {
            String fileName = getText ("dict_importTemplate");
            Order order = new Order ();
            List <Order> list = orderService.findAllListExport (order);
            List <DesignOption> designOptionList = orderService.getdesignList ();
            for (Order order1 : list) {
                order1.setUrgentCD (DictUtils.getDictName (order1.getUrgentCD ()));
                order1.setOrderTypeCD (DictUtils.getDictName (order1.getOrderTypeCD ()));
                order1.setSizeCD (DictUtils.getDictName (order1.getSizeCD ()));
                for (DesignOption designOption : designOptionList) {
                    if ((order1.getShirtSgd ().trim ()).equals ((designOption.getItemValue ().trim ()))) {
                        order1.setShirtSgd (designOption.getItemNameCN ());
                    }
                }
                order1.setOrderStatusCD (DictUtils.getDictName (order1.getOrderStatusCD ()));
            }
            // order_made :定制订单
            new ExportExcel (getText ("order_made"), Order.class, 2).setDataList (list).write (response, fileName).dispose ();
            return null;
        } catch (Exception e) {
            // 记录日志
            logger.error (e.getMessage (), e);
        }
        // 提示错误信息
        return renderString (response, AjaxDone.error (getText ("System_error_please_contact_your_administrator")));

    }

    /**
     * cell值转换
     *
     * @param val
     * @return
     */
    public String valuechangeR(String val) {

        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "";
        } else {
            String[] arryVal = val.split (":");
            if (arryVal.length > 1) {
                return arryVal[1];
            }
        }
        return val;
    }

    /**
     * cell值转换
     *
     * @param val
     * @return
     */
    public String valuechange(String val) {

        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "";
        } else {
            String[] arryVal = val.split ("/");
            if (arryVal.length > 1) {
                return arryVal[0].replace(".", "").trim ();
            }
        }
        return val.trim ();
    }

    /**
     * 刺绣颜色cell值转换
     *
     * @param val
     * @return
     */
    public String valuechangeSMC(String val) {

        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "";
        } else {

            val = val.trim ().replace (".0", "");
            if (StringUtils.isNumeric (val) == true) {
                val = String.format ("%04d", Integer.parseInt (val));
                return val.trim ();
            } else {
                val = val.replaceAll ("[^a-z^A-Z]", "");
                return val.trim ();
            }

        }
    }

    /**
     * cell值转换(.)
     *
     * @param val
     * @return
     */
    public String valuechangeSpot(String val) {

        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "";
        } else {
            String[] arryVal = val.split ("/");
            if (arryVal.length > 1) {
                return arryVal[0].replace (".", "").trim ();
            }
        }
        return val.replace (".", "").trim ();
    }

    /**
     * cell值转换(面料code)
     *
     * @param val
     * @return
     */
    public String valuechangeMC(String val) {

        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "";
        }
        return val.trim ();
    }

    /**
     * cell值转换(量体项目值转换)
     *
     * @param val
     * @return
     */
    public String valuechangeInt(String val) {
        // 获取当前的cell值
        if (val == null || "".equals (val.trim ()) || "-".equals (val.trim ())) {
            return "-";
        } else {
            String[] arryVal = val.split ("\\(");
            if (arryVal.length > 1) {
                return arryVal[0];
            }
        }
        return val;
    }

    /**
     * 获取单元格的值
     *
     * @param cell
     * @return
     */
    public String getCellValue(Cell cell) {
        if (cell == null) return "";
        if (cell.getCellType () == Cell.CELL_TYPE_STRING) {
            return cell.getStringCellValue ();
        } else if (cell.getCellType () == Cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf (cell.getBooleanCellValue ());
        } else if (cell.getCellType () == Cell.CELL_TYPE_FORMULA) {
            return cell.getCellFormula ();
        } else if (cell.getCellType () == Cell.CELL_TYPE_NUMERIC) {
            return cell.getNumericCellValue () + "";
        }
        return "";
    }
    
    
    // 初始箱单信息文件名
    public static final String ENCHASE_INFO_NORMAL_EXCEL_NAME = "NORMAL_ENCHASE";
    // 补充箱单信息文件名
    public static final String ENCHASE_INFO_SUPPLEMENT_EXCEL_NAME = "SUPPLEMENT_ENCHASE";
	/**
	 * 导入Excel装箱信息
	 *
	 * @param file
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "updateOrderData", method = RequestMethod.POST)
	@ResponseBody
	public String updateOrderData(MultipartFile file, HttpServletResponse response) throws Exception {
		String oldFlg = "false";
		try {
			List<Order> orderList = new ArrayList<>();
			String fileName = file.getOriginalFilename();
			String fileFlag = "";
			if (fileName.indexOf(ENCHASE_INFO_NORMAL_EXCEL_NAME) == -1 && fileName.indexOf(ENCHASE_INFO_SUPPLEMENT_EXCEL_NAME) == -1) {
				return renderString(response, AjaxDone.error("导入失败，请注意文件名格式"));
			}
			ImportExcel ei = new ImportExcel(file, 1, 0);
			Workbook workbook = ei.wb;
			Sheet st = workbook.getSheetAt(0);
			int rowmun = st.getPhysicalNumberOfRows();
			String cellStr;
			// 订单实体类
			Order order = new Order();
			Order order2 = new Order();
			if (fileName.indexOf(ENCHASE_INFO_NORMAL_EXCEL_NAME) != -1) {
				fileFlag = ENCHASE_INFO_NORMAL_EXCEL_NAME;
				for (int i = 1; i < rowmun; i++) {
					if (st.getRow(i)!=null) {
						// 客户订单号 (A)
						cellStr = getCellValue(st.getRow(i).getCell(0));
						if (!"".equals(cellStr)) {
							order2 = orderService.checkOrderExist(cellStr);
							if (order2==null) {
								return renderString(response,AjaxDone.error(cellStr.toString()+"订单不存在"));
							}
							order.setId(order2.getId());
							order.setOrderNO(order2.getOrderNO());
							order.setCustomOrderNo(cellStr);
							//装箱信息导入状态
							order.setCartonInfoStatus(order2.getCartonInfoStatus());
							// Transit group(B)
							cellStr = getCellValue(st.getRow(i).getCell(2));
							order.setTransitGroup(cellStr);
							// Country(C)
							cellStr = getCellValue(st.getRow(i).getCell(3));
							order.setCountryName(cellStr);
							orderList.add(order);
							order = new Order();
						}
					}
				}
			}else if (fileName.indexOf(ENCHASE_INFO_SUPPLEMENT_EXCEL_NAME) != -1){
				fileFlag = ENCHASE_INFO_SUPPLEMENT_EXCEL_NAME;
				for (int i = 1; i < rowmun; i++) {
					if (st.getRow(i)!=null) {
						// 客户订单号 (A)
						cellStr = getCellValue(st.getRow(i).getCell(0));
						if (!"".equals(cellStr)) {
							order2 = orderService.checkOrderExist(cellStr);
							if (order2==null) {
								return renderString(response,AjaxDone.error(cellStr.toString()+"订单不存在"));
							}
							order.setId(order2.getId());
							order.setOrderNO(order2.getOrderNO());
							order.setCustomOrderNo(cellStr);
							//装箱信息导入状态
							order.setCartonInfoStatus(order2.getCartonInfoStatus());
							//Shop Order No(C)
							cellStr = getCellValue(st.getRow(i).getCell(2));
							order.setShopOrderNo(cellStr);
							//Shop name(D)
							cellStr = getCellValue(st.getRow(i).getCell(3));
							order.setShopName(cellStr);
							//Tailor(E)
							cellStr = getCellValue(st.getRow(i).getCell(4));
							order.setTailor(cellStr);
							//Customer(F)
							cellStr = getCellValue(st.getRow(i).getCell(5));
							order.setCustomName(cellStr);
							//Shipping Destination Code(G)
							cellStr = getCellValue(st.getRow(i).getCell(6));
							order.setShippingDestinationCode(cellStr);
							//Hanger Size(H)
							cellStr = getCellValue(st.getRow(i).getCell(7));
							order.setHangerSize(cellStr);
							//Make(I)
							cellStr = getCellValue(st.getRow(i).getCell(8));
							order.setMakeShirt(cellStr);
							//Item(J)
							cellStr = getCellValue(st.getRow(i).getCell(9));
							order.setItem(cellStr);
							orderList.add(order);
							order = new Order();
						}
					}
				}
			}
			// excel数据导入
			orderService.updateOrderData(orderList,fileFlag); 
			oldFlg = "true";
		} catch (Exception e) {
			// 返回提示信息
			logger.error(e.getMessage(),e);
			return renderString(response,AjaxDone.error(getText("System_error_please_contact_your_administrator")));
		}
		return renderString(response, oldFlg);
	}
	
	
	/**
	 * 小样Excel信息导入
	 *
	 * @param file
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "importSampleExcelData", method = RequestMethod.POST)
	@ResponseBody
	public String importSampleExcelData(MultipartFile file, HttpServletResponse response,HttpServletRequest request,String customName,Long venderID,String orderType){
		String oldFlg = "false";
		try {
			//小样：基本信息数据集
			List<StyleDesignHistoryEntity> cloudList = sampleInfo(file,response);
			Long contractId = orderService.insertExcelDataBefore(cloudList, customName, venderID, orderType, "ERP",null,null);
			oldFlg = "true";
			//导入成功给指定人员发送邮件
            CustomizationContract contract = orderService.getContractInfo(contractId);
            String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
				        + request.getContextPath() + Global.getAdminPath() + "/customization/order/order?contractID="
				        + contract.getId() + "&contractNo=" + contract.getContractNO() + "&imageFlag=customizationContract&contractDate=" + DateUtils.formatDate(contract.getCreateDate(), "yyyy-MM-dd");
            SendEmailMessage sendEmailMessage = new SendEmailMessage();
            sendEmailMessage.setDataTheme(ResourcesUtil.getConfig("erp_send_mail_theme01"));
            sendEmailMessage.setDataMessage(ResourcesUtil.getConfig("erp_send_mail_textMessage01"));
            sendEmailMessage.setDataXXX01(UserUtils.getUser().getFirstName()+UserUtils.getUser().getLastName());
            sendEmailMessage.setDataXXX02(contract.getContractNO());
            sendEmailMessage.setDataXXX03(contract.getOrderQuantity());
            sendEmailMessage.setDataXURLX(url);
            sendEmailMessage.setDataYYMMDD01(DateUtils.formatDate(contract.getCreateDate(), "yyyy-MM-dd").toString());
            sendEmailMessage.setDataYYMMDD02(DateUtils.formatDate(contract.getContractDeliveryDate(), "yyyy-MM-dd") + " / " + DateUtils.formatDate(contract.getContractDeliveryHDate(), "yyyy-MM-dd"));
            //发送邮件
            UserUtils.sendEmail(sendEmailMessage);
		} catch (Exception e) {
			// 返回提示信息
			logger.error(e.getMessage(),e);
			oldFlg = e.getMessage();
		}
		return renderString(response, oldFlg);
	}
	
	/**
	 * 小样：基本信息
	 */
	public List<StyleDesignHistoryEntity> sampleInfo(MultipartFile file, HttpServletResponse response) throws Exception {
		//小样：面料信息数据集
		List<SampleFabric> sampleFabricList = sample_Fabric(file);
		//小样：刺绣信息数据集
		List<SampleBreastPocket> sampleBreastPocketList = sample_BreastPocket(file);
		//小样：领子信息数据集
		List<SampleCollar> sampleCollarList = sample_Collar(file);
		//小样：袖头信息数据集
		List<SampleCuff> sampleCuffList = sample_Cuff(file);
		//小样：手绢信息数据集
		List<SampleHandkerChief> sampleHandkerChiefList = sample_HandkerChief(file);
		// 订单数据采集实体
		StyleDesignHistoryEntity cloudEntity = new StyleDesignHistoryEntity();
		//
		List<StyleDesignHistoryEntity> cloudList = new ArrayList<>();
		//
		SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
		// 日期初期化
        Date dateCell = new Date ();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(0);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					cloudEntity.setOrderNo(cellStr.trim());
					// Item type
					cellStr = getCellValue(st.getRow(i).getCell(1));
					// 面料
					if ("Fabric".equals(cellStr)) {
						if (sampleFabricList != null && sampleFabricList.size() > 0) {
							cloudEntity.setStyleNameCn(cellStr+":小样面料");
							cloudEntity.setSampleFlag(cellStr);
							for (SampleFabric sFabric : sampleFabricList) {
								if (cloudEntity.getOrderNo().equals(sFabric.getOrderNo())) {
									//面料号
									cloudEntity.setFabricCode(sFabric.getFabricCode().split("/")[0].trim());
									//数量
									cloudEntity.setQuantity(new BigDecimal(sFabric.getQuantity()));
								}
							}
						}
					// 刺绣	
					}else if ("BreastPocket".equals(cellStr)) {
						if (sampleBreastPocketList != null && sampleBreastPocketList.size() > 0) {
							cloudEntity.setStyleNameCn(cellStr+":小样刺绣");
							cloudEntity.setSampleFlag(cellStr);
							for (SampleBreastPocket sBreastPocket : sampleBreastPocketList) {
								if (cloudEntity.getOrderNo().equals(sBreastPocket.getOrderNo())) {
									//面料号
									cloudEntity.setFabricCode(sBreastPocket.getFabricCode().split("/")[0].trim());
									//缝制方式
									cloudEntity.setModelSma(valuechange(sBreastPocket.getMakeType()));
									//刺绣内容
									cloudEntity.setEmbrText(sBreastPocket.getEmbroideryText().replace(",", "&#44"));
									//刺绣颜色
									cloudEntity.setEmbrSmc(valuechangeSMC(sBreastPocket.getEmbroideryColor()));
									//刺绣字体
									cloudEntity.setEmbrSmo(valuechange (sBreastPocket.getEmbroideryLetterType()));
									//刺绣位置
									cloudEntity.setEmbrSmp(valuechange (sBreastPocket.getEmbroideryPosition()).replace (" ", ""));
									//刺绣大小
									cloudEntity.setEmbrSms(valuechange (sBreastPocket.getEmbroiderySize()).replace (" ", ""));
								}
							}
						}
					// 领子	
					}else if ("Collar".equals(cellStr)) {
						if (sampleCollarList != null && sampleCollarList.size() > 0) {
							cloudEntity.setStyleNameCn(cellStr+":小样领子");
							cloudEntity.setSampleFlag(cellStr);
							for (SampleCollar sCollar : sampleCollarList) {
								// 领子
								cloudEntity.setModelSco(sCollar.getCollar());
								// 面料号
								cloudEntity.setFabricCode(sCollar.getFabricCode().split("/")[0].trim());
								// 缝制方式
								cloudEntity.setModelSma(valuechange(sCollar.getMakeType()));
								// 衬布
								cloudEntity.setModelSsk(sCollar.getSkinning());
								// 插签
								cloudEntity.setModelSbo(sCollar.getCollarBones());
								// 明线
								cloudEntity.setModelSst(sCollar.getStitching());
								// 扣
								cloudEntity.setTrimSbu(sCollar.getButton());
								// 扣眼颜色
								cloudEntity.setTrimSbh(sCollar.getButtonholeColor());
								// 钉扣方法
								cloudEntity.setTrimSat(sCollar.getButtonAttachment());
								// 钉扣线色
								cloudEntity.setTrimSbt(sCollar.getButtonAttachmentColor());
								// 领子配色线
								cloudEntity.setTrimSts(sCollar.getTopStitching());
							}
						}
					// 袖头	
					}else if ("Cuff".equals(cellStr)) {
						if (sampleCuffList != null && sampleCuffList.size() > 0) {
							cloudEntity.setStyleNameCn(cellStr+":小样袖头");
							cloudEntity.setSampleFlag(cellStr);
							for (SampleCuff sCuff : sampleCuffList) {
								if (cloudEntity.getOrderNo().equals(sCuff.getOrderNo())) {
									// 袖头
									cloudEntity.setModelScu(sCuff.getCuff());
									// 面料号
									cloudEntity.setFabricCode(sCuff.getFabricCode().split("/")[0].trim());
									// 缝制方式
									cloudEntity.setModelSma(valuechange(sCuff.getMakeType()));
									// 衬布
									cloudEntity.setModelSsk(sCuff.getSkinning());
									// 明线
									cloudEntity.setModelSst(sCuff.getStitching());
									// 扣
									cloudEntity.setTrimSbu(sCuff.getButton());
									// 扣眼颜色
									cloudEntity.setTrimSbh(sCuff.getButtonholeColor());
									// 钉扣方法
									cloudEntity.setTrimSat(sCuff.getButtonAttachment());
									// 钉扣线色
									cloudEntity.setTrimSbt(sCuff.getButtonAttachmentColor());
									// 刺绣内容
									cloudEntity.setEmbrText(sCuff.getEmbroideryText().replace(",", "&#44"));
									// 刺绣颜色
									cloudEntity.setEmbrSmc(valuechangeSMC(sCuff.getEmbroideryColor()));
									// 刺绣字体
									cloudEntity.setEmbrSmo(valuechange (sCuff.getEmbroideryLetterType()));
									// 刺绣位置
									cloudEntity.setEmbrSmp(valuechange (sCuff.getEmbroideryPosition()).replace (" ", ""));
									// 刺绣大小
									cloudEntity.setEmbrSms(valuechange (sCuff.getEmbroiderySize()).replace (" ", ""));
									// 右袖头尺寸
									cloudEntity.setSizeClr(sCuff.getCuffLengthR());
									// 左袖头尺寸
									cloudEntity.setSizeCll(sCuff.getCuffLengthL());
								}
							}
						}
					// 手绢	
					}else if ("HandkerChief".equals(cellStr)) {
						if (sampleHandkerChiefList != null && sampleHandkerChiefList.size() > 0) {
							cloudEntity.setStyleNameCn(cellStr+":小样手绢");
							cloudEntity.setSampleFlag(cellStr);
							for (SampleHandkerChief sHandkerChief : sampleHandkerChiefList) {
								if (cloudEntity.getOrderNo().equals(sHandkerChief.getOrderNo())) {
									//面料号
									cloudEntity.setFabricCode(sHandkerChief.getFabricCode().split("/")[0].trim());
									//缝制方式
									cloudEntity.setModelSma(valuechange(sHandkerChief.getMakeType()));
								}
							}
						}
					}
					// Product
					cellStr = getCellValue(st.getRow(i).getCell(2));
					// DesignOption
					cellStr = getCellValue(st.getRow(i).getCell(3));
					// Item name
					cellStr = getCellValue(st.getRow(i).getCell(4));
					// Item production code
					cellStr = getCellValue(st.getRow(i).getCell(5));
					// Qty
					cellStr = getCellValue(st.getRow(i).getCell(6));
					// Button qty (big)
					cellStr = getCellValue(st.getRow(i).getCell(7));
					// Button qty (small)
					cellStr = getCellValue(st.getRow(i).getCell(8));
					// Added by
					cellStr = getCellValue(st.getRow(i).getCell(9));
					// Shop Id
					cellStr = getCellValue(st.getRow(i).getCell(10));
					// Shop name 店铺名称
					cellStr = getCellValue(st.getRow(i).getCell(11));
					cloudEntity.setShopName(cellStr);
					// Sales representative
					cellStr = getCellValue(st.getRow(i).getCell(12));
					// Status
					cellStr = getCellValue(st.getRow(i).getCell(13));
					// Shipment date 船期
					//cellStr = getCellValue(st.getRow(i).getCell(14));
					cellStr = sdf.format (HSSFDateUtil.getJavaDate (st.getRow (i).getCell (14).getNumericCellValue ()));
                    dateCell = sdf.parse (cellStr);
					cloudEntity.setShipmentDate(dateCell);
					// Updated shipment date
					cellStr = getCellValue(st.getRow(i).getCell(15));
					// Shipping destination 目的地
					cellStr = getCellValue(st.getRow(i).getCell(16));
					cloudEntity.setShippingDestination(cellStr);
					// Remarks
					cellStr = getCellValue(st.getRow(i).getCell(17));
					// Monogram Size
					cellStr = getCellValue(st.getRow(i).getCell(18));
					cloudList.add(cloudEntity);
					cloudEntity = new StyleDesignHistoryEntity();
				}
			}
		}
		return cloudList;
	}
	
	/**
	 * 小样：面料 fabric
	 */
	public List<SampleFabric> sample_Fabric(MultipartFile file) throws Exception {
		//小样面料实体
		SampleFabric sFabric = new SampleFabric();
		//小样面料集合
		List<SampleFabric> sList = new ArrayList<>();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(1);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					sFabric.setOrderNo(cellStr.trim());
					// 面料号
					cellStr = getCellValue(st.getRow(i).getCell(1));
					sFabric.setFabricCode(cellStr);
					// 数量
					cellStr = getCellValue(st.getRow(i).getCell(2));
					sFabric.setQuantity(cellStr);
					sList.add(sFabric);
					sFabric = new SampleFabric();
				}
			}
		}
		return sList;
	}
	
	/**
	 * 小样：刺绣 BreastPocket
	 */
	public List<SampleBreastPocket> sample_BreastPocket(MultipartFile file) throws Exception {
		//小样刺绣实体
		SampleBreastPocket sBreastPocket = new SampleBreastPocket();
		//小样刺绣集合
		List<SampleBreastPocket> sList = new ArrayList<>();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(2);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					sBreastPocket.setOrderNo(cellStr.trim());
					// 数量
					cellStr = getCellValue(st.getRow(i).getCell(1));
					sBreastPocket.setQuantity(cellStr);
					// 型号
					cellStr = getCellValue(st.getRow(i).getCell(2));
					sBreastPocket.setModel(cellStr);
					// 面料号
					cellStr = getCellValue(st.getRow(i).getCell(3));
					sBreastPocket.setFabricCode(cellStr);
					// 缝制方式
					cellStr = getCellValue(st.getRow(i).getCell(4));
					sBreastPocket.setMakeType(cellStr);
					// 刺绣内容
					cellStr = getCellValue(st.getRow(i).getCell(5));
					sBreastPocket.setEmbroideryText(cellStr);
					// 刺绣字体
					cellStr = getCellValue(st.getRow(i).getCell(6));
					sBreastPocket.setEmbroideryLetterType(cellStr);
					// 刺绣位置
					cellStr = getCellValue(st.getRow(i).getCell(7));
					sBreastPocket.setEmbroideryPosition(cellStr);
					// 刺绣颜色
					cellStr = getCellValue(st.getRow(i).getCell(8));
					sBreastPocket.setEmbroideryColor(cellStr);
					// 刺绣大小
					cellStr = getCellValue(st.getRow(i).getCell(9));
					sBreastPocket.setEmbroiderySize(cellStr);
					sList.add(sBreastPocket);
					sBreastPocket = new SampleBreastPocket();
				}
			}
		}
		return sList;
	}
	
	/**
	 * 小样：领子 Collar
	 */
	public List<SampleCollar> sample_Collar(MultipartFile file) throws Exception {
		//小样领子实体
		SampleCollar sCollar = new SampleCollar();
		//小样领子集合
		List<SampleCollar> sList = new ArrayList<>();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(3);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					sCollar.setOrderNo(cellStr.trim());
					// 数量
					cellStr = getCellValue(st.getRow(i).getCell(1));
					sCollar.setQuantity(cellStr);
					// 规格
					cellStr = getCellValue(st.getRow(i).getCell(2));
					sCollar.setCollarSpec(cellStr);
					// 领子
					cellStr = getCellValue(st.getRow(i).getCell(3));
					sCollar.setCollar(cellStr);
					// 面料号
					cellStr = getCellValue(st.getRow(i).getCell(4));
					sCollar.setFabricCode(cellStr);
					// 缝制方式
					cellStr = getCellValue(st.getRow(i).getCell(5));
					sCollar.setMakeType(cellStr);
					// 衬布
					cellStr = getCellValue(st.getRow(i).getCell(6));
					sCollar.setSkinning(cellStr);
					// 插签
					cellStr = getCellValue(st.getRow(i).getCell(7));
					sCollar.setCollarBones(cellStr);
					// 明线
					cellStr = getCellValue(st.getRow(i).getCell(8));
					sCollar.setStitching(cellStr);
					// 扣
					cellStr = getCellValue(st.getRow(i).getCell(9));
					sCollar.setButton(cellStr);
					// 扣眼颜色
					cellStr = getCellValue(st.getRow(i).getCell(10));
					sCollar.setButtonholeColor(cellStr);
					// 钉扣方法
					cellStr = getCellValue(st.getRow(i).getCell(11));
					sCollar.setButtonAttachment(cellStr);
					// 钉扣线色
					cellStr = getCellValue(st.getRow(i).getCell(12));
					sCollar.setButtonAttachmentColor(cellStr);
					// 领子配色线
					cellStr = getCellValue(st.getRow(i).getCell(13));
					sCollar.setTopStitching(cellStr);
					sList.add(sCollar);
					sCollar = new SampleCollar();
				}
			}
		}
		return sList;
	}
	
	/**
	 * 小样：袖头 Cuff
	 */
	public List<SampleCuff> sample_Cuff(MultipartFile file) throws Exception {
		//小样袖头实体
		SampleCuff sCuff = new SampleCuff();
		//小样袖头集合
		List<SampleCuff> sList = new ArrayList<>();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(4);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					sCuff.setOrderNo(cellStr.trim());
					// 数量
					cellStr = getCellValue(st.getRow(i).getCell(1));
					sCuff.setQuantity(cellStr);
					// 袖子
					cellStr = getCellValue(st.getRow(i).getCell(2));
					sCuff.setCuff(cellStr);
					// 面料号
					cellStr = getCellValue(st.getRow(i).getCell(3));
					sCuff.setFabricCode(cellStr);
					// 缝制方式
					cellStr = getCellValue(st.getRow(i).getCell(4));
					sCuff.setMakeType(cellStr);
					// 衬布
					cellStr = getCellValue(st.getRow(i).getCell(5));
					sCuff.setSkinning(cellStr);
					// 明线
					cellStr = getCellValue(st.getRow(i).getCell(6));
					sCuff.setStitching(cellStr);
					// 扣
					cellStr = getCellValue(st.getRow(i).getCell(7));
					sCuff.setButton(cellStr);
					// 钉扣方法
					cellStr = getCellValue(st.getRow(i).getCell(8));
					sCuff.setButtonAttachment(cellStr);
					// 钉扣线色
					cellStr = getCellValue(st.getRow(i).getCell(9));
					sCuff.setButtonAttachmentColor(cellStr);
					// 扣眼颜色
					cellStr = getCellValue(st.getRow(i).getCell(10));
					sCuff.setButtonholeColor(cellStr);
					// 刺绣内容
					cellStr = getCellValue(st.getRow(i).getCell(11));
					sCuff.setEmbroideryText(cellStr);
					// 刺绣字体
					cellStr = getCellValue(st.getRow(i).getCell(12));
					sCuff.setEmbroideryLetterType(cellStr);
					// 刺绣位置
					cellStr = getCellValue(st.getRow(i).getCell(13));
					sCuff.setEmbroideryPosition(cellStr);
					// 刺绣颜色
					cellStr = getCellValue(st.getRow(i).getCell(14));
					sCuff.setEmbroideryColor(cellStr);
					// 刺绣大小
					cellStr = getCellValue(st.getRow(i).getCell(15));
					sCuff.setEmbroiderySize(cellStr);
					// 右袖头尺寸
					cellStr = getCellValue(st.getRow(i).getCell(16));
					sCuff.setCuffLengthR(cellStr);
					// 左袖头尺寸
					cellStr = getCellValue(st.getRow(i).getCell(17));
					sCuff.setCuffLengthL(cellStr);
					sList.add(sCuff);
					sCuff = new SampleCuff();
				}
			}
		}
		return sList;
	}
	
	/**
	 * 小样：手绢 HandkerChief
	 */
	public List<SampleHandkerChief> sample_HandkerChief(MultipartFile file) throws Exception {
		//小样手绢实体
		SampleHandkerChief sHandkerChief = new SampleHandkerChief();
		//小样手绢集合
		List<SampleHandkerChief> sList = new ArrayList<>();
		//获取Excel文件
		ImportExcel ei = new ImportExcel(file, 1, 0);
		//获取工作簿
		Workbook workbook = ei.wb;
		//获取工作簿指定sheet页（下标0开始，第一页为0.第二页为1，以此类推）
		Sheet st = workbook.getSheetAt(5);
		//获取sheet页有效数据行数
		int rowmun = st.getPhysicalNumberOfRows();
		//单元格数据
		String cellStr;
		for (int i = 1; i < rowmun; i++) {
			if (st.getRow(i)!=null) {
				// 订单号 Order number
				cellStr = getCellValue(st.getRow(i).getCell(0));
				if (!"".equals(cellStr)) {
					sHandkerChief.setOrderNo(cellStr.trim());
					// 数量
					cellStr = getCellValue(st.getRow(i).getCell(1));
					sHandkerChief.setQuantity(cellStr);
					// 面料号
					cellStr = getCellValue(st.getRow(i).getCell(2));
					sHandkerChief.setFabricCode(cellStr);
					// 缝制方式
					cellStr = getCellValue(st.getRow(i).getCell(3));
					sHandkerChief.setMakeType(cellStr);
					sList.add(sHandkerChief);
					sHandkerChief = new SampleHandkerChief();
				}
			}
		}
		return sList;
	}
	
//-------------------------------------------定制合同-----------------------------------------------------------//
    
    

    /**
     * 大货订单一览画面
     *
     * @return
     */
    @RequestMapping(value = {""})
    public String customizationContract() {
        return "modules/order/customizationContract";
    }

    /**
     * 拼接一览画面
     *
     * @param values
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"searchContractList"})
    @ResponseBody
    public String searchContractList(CustomizationContract customizationContract, HttpServletRequest request, HttpServletResponse response,
                             Model model, String[] values) throws Exception {
        Map <Object, Object> listMap = new HashMap <Object, Object> ();
        // ajax回调时使用的一览list名
        request.setAttribute ("listNames", "customizationContract");
        // 画面取得的检索项目
        String contractNO = customizationContract.getContractNO ();
        // 客户名称
        String venderName = customizationContract.getVenderName ();
        // 开始日期
        String dateStart = customizationContract.getDateStart ();
        // 截止日期
        String dateEnd = customizationContract.getDateEnd ();
        // 拼接字符串供分页使用
        String searchParam = "&contractNO=" + contractNO + "&venderName=" + venderName + "&dateStart=" + dateStart + "&dateEnd=" + dateEnd;
        //放到Attribute里，使用Global类里面的SEARCH_PAEAM作为key
        request.setAttribute (Global.SEARCH_PAEAM, searchParam);
        // 查询一览页面数据
        Page <CustomizationContract> page = orderService.findCustomizationContractList (new Page <CustomizationContract> (request, response),
        		customizationContract);
        // 读取文件生成字符串
        String strUri = request.getContextPath () + Global.getAdminPath ();
        String strHtml = "";
        Map <String, Object> map = new HashedMap ();
        map.put ("adminUri", strUri);
        map.put ("contractList", page.getList ());
        map.put ("pageNo", page.getPageNo ());
        map.put ("pageSize", page.getPageSize ());
        map.put("springMacroRequestContext", new RequestContext (request));
        strHtml = FreeMarkerTemplateUtils
                .processTemplateIntoString (freemarkerConfiguration.getTemplate ("customizationContractList.ftl"), map);
        listMap.put ("customizationContract", strHtml);
        listMap.put ("page", page.getHtml ());
        // ajax返回结果
        return renderString (response, listMap);
    }

    /**
     * 查看一条大货订单信息
     *
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "contractDetail")
    public String contractDetail(Long contractId, HttpServletRequest request, HttpServletResponse response,
                                    Model model) {
    	CustomizationContract customizationContract = new CustomizationContract();
    	customizationContract = orderService.getContractInfo (contractId);
        model.addAttribute ("customizationContract", customizationContract);
        return "modules/order/customizationContractShow";
    }
    /**
     *
     *
     * @return
     */
    @RequiresPermissions("customization:order:edit")
    @RequestMapping(value = "updateUrgentCd")
    public String updateUrgentCd(String urgentCD,String orderNO,HttpServletRequest request, HttpServletResponse response) throws Exception{
        String flag = "false";
        try {
            orderService.updateUrgentCd (urgentCD,orderNO);
            orderService.updateTempOorderByOrderNO(urgentCD,orderNO);
            flag = "true";
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }

        return renderString(response,flag);
    }
    
    /**
     * 查看一条定制订单信息
     *
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "contract")
    public String contract(String styleId,HttpServletRequest request, HttpServletResponse response,
                                    Model model) {
    	OrderListShowEntity orderListShowEntity = new OrderListShowEntity();
    	orderListShowEntity = orderService.getOrderInfo(styleId);
    	List<OrderListShowEntity> shirtStyleList = orderService.getShirtStyle(styleId);
    	model.addAttribute ("orderListShowEntity", orderListShowEntity);
    	model.addAttribute ("shirtStyleList", shirtStyleList);
        return "modules/order/orderListShow";
    }
    
    /**
     * 终止进程
     *
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "stopTread")
    public String stopTread(HttpServletRequest request, HttpServletResponse response) {
    	stopFlag = true;
    	System.out.println("----------------------------------终止成功了吗？------------------------------");
    	return renderString(response,"");
    }
    
    /**
     * 导出合同费用明细数据
     *
     * @param response
     * @return
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = "exportContractCostDetails")
    public String exportContractCostDetails(String contractNo ,HttpServletResponse response) {
        try {
        	SXSSFWorkbook wb = new SXSSFWorkbook ();
            List<ExportCostEntity> list = orderService.findContractCostDetails(contractNo);
            if (list == null) {
            	// 提示错误信息
                return renderString (response, "false");
			}
            // 费用
            new ExportExcel ("费用明细", wb, contractNo+" 合同费用明细", ExportCostEntity.class, 2).setDataList (list);
            skCost = wb;
            return renderString (response,"true");
        } catch (Exception e) {
            // 记录日志
            logger.error (e.getMessage (), e);
        }
        // 提示错误信息
        return renderString (response, "error");
    }
    
    /**
     * Excel下载
     *
     * @param response
     * @return
     * @throws Exception
     */
    @RequiresPermissions("customization:order:view")
    @RequestMapping(value = {"makeCostExcelFile"})
    public void makeCostExcelFile(String contractNo,HttpServletResponse response, HttpServletRequest request)
            throws Exception {
    	String fileName = contractNo + "合同费用明细.xlsx";
        response.reset ();
        response.setContentType ("application/octet-stream; charset=utf-8");
        response.setCharacterEncoding ("UTF-8");
        response.setHeader ("Content-Disposition", "attachment; filename=" + new String (fileName.getBytes (), "ISO-8859-1"));
        skCost.write (response.getOutputStream ());
    }
    
    /**
     * 导入订单费用画面
     *
     * @return
     */
    @RequestMapping(value = {"importOrderCostHtml"})
    public String importOrderCostHtml() {
        return "modules/order/uploadFileOrderCost";
    }
    
    /**
	 * 导入Excel订单费用
	 *
	 * @param file
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "importOrderCost", method = RequestMethod.POST)
	@ResponseBody
	public String importOrderCost(MultipartFile file, HttpServletResponse response) throws Exception {
		String oldFlg = "false";
		try {
			List<Order> orderList = new ArrayList<>();
			ImportExcel ei = new ImportExcel(file, 1, 0);
			Workbook workbook = ei.wb;
			Sheet st = workbook.getSheetAt(0);
			int rowmun = st.getPhysicalNumberOfRows();
			String cellStr;
			// 订单实体类
			Order order = new Order();
			for (int i = 2; i < rowmun; i++) {
				if (st.getRow(i)!=null) {
					// 订单号 (C)
					cellStr = getCellValue(st.getRow(i).getCell(2));
					if (!"".equals(cellStr)) {
						order.setOrderNO(cellStr);
						// 订单费用(K:备注)
						cellStr = getCellValue(st.getRow(i).getCell(10));
						order.setStrCost(cellStr);
						orderList.add(order);
						order = new Order();
					}
				}
			}
			
			// excel数据导入
			String returnStr = orderService.saveOrderCost(orderList); 
			if (!"IMPORT_SUCCESS".equals(returnStr)) {
				return renderString(response,AjaxDone.error(returnStr+"订单不存在 或 订单费用为空"));
			}
			oldFlg = "true";
		} catch (Exception e) {
			// 返回提示信息
			logger.error(e.getMessage(),e);
			return renderString(response,AjaxDone.error("系统错误，请联系管理员！"));
		}
		return renderString(response, oldFlg);
	}
	
	/**
	 * 同步平台订单数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "syncMtmData")
	@ResponseBody
	public String syncMtmData(String flg,HttpServletRequest request,HttpServletResponse response){
		String returnMsg = "fail";
		// 春衫订单同步
		if ("1".equals(flg)) {
			returnMsg = mtMtoERPDataBaseSyncJob.dataBaseSync();
		// Mark订单同步
		}else if ("2".equals(flg)) {
			returnMsg = mtMtoERPDataBaseSyncJob.dataBaseSync_Mark();
		}
		return renderString(response, returnMsg);
	}
}
